<?php
define ("PREG_MAIL", "/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9\.\-\_]+\.[A-Za-z]{2,3}$/i");
define ("PREG_TIME", "/^\d{2}:\d{2}$/");
define ("PREG_DATE", "/^\d{2}-\d{2}-\d{4}$/");
function EmailValidator(&$email)
{
	if (!trim($email))
	{
		return true;
	}

	if (preg_match(PREG_MAIL, trim($email)))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function EmailCorrect(&$email)
{

	if (!trim($email))
	{
		return true;
	}
	if (preg_match(PREG_MAIL, trim($email)))
	{
		return true;
	}
	else
	{
		return false;
	}
}

/*function MailUnique(&$email,&$field)
{
if (preg_match(PREG_MAIL, trim($email)))
{
if (FieldUnique($email,"email"))
{
return true;
}
}
else
{
return false;
}
}
*/


function noValidation(&$str)
{
	return true;
}


function correctTime(&$email)
{
	if (!trim($email))
	{
		return true;
	}

	if (preg_match(PREG_TIME, trim($email)))
	{
		return true;
	}
	else
	{
		return false;
	}
}


function isNumeric($str)
{
	if (!trim($str))
	{
		return true;
	}

	if (is_numeric($str))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function correctDate(&$email)
{
	if (!trim($email))
	{
		return true;
	}

	if (preg_match(PREG_DATE, trim($email)))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function isnot_empty(&$str)
{
	if (strlen(trim($str))>1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function isnot_zero(&$str)
{
	if ((trim($str))!=0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function lenthTopicCorrect(&$str,&$extraParam)
{
	if (strlen(trim($str))<=$extraParam && strlen(trim($str))>1)
	{
		return true;
	}
	else
	{
		return false;
	}
}


function FieldUnique(&$str,&$extraParam)
{

	if ($str)
	{
		$tableName = $extraParam[0];
		$field=$extraParam[1];
		$table = new CARXTable($tableName,"$field='$str'",$field);
		$table->Open();

		return $table->GetRowCount();
	}
}


function CheckFileType(&$file,&$allowedTypes)
{
	if ($file)
	{
		if (in_array($file,$allowedTypes))	return true;
		else return false;
	}
	else
	{
		return true;
	}

}

function CheckFileSize(&$file,&$size)
{
	if ($file)
	{
		if ($file<=$size)
		{
			return true;
		}
		else
		{
			return false;
		}

	}
	else
	{
		return true;
	}
}


/*Array
(
[attachment] => Array
(
[name] => cdk[1].sql.zip
[type] => application/zip
[tmp_name] => C:\WINDOWS\TEMP\php15A.tmp
[error] => 0
[size] => 22429
)

)*/

?>